home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / cardpkg_1.3.lha / CardPkg / CardHImages.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-19  |  4.6 KB  |  151 lines

  1. /************************************************************
  2.  
  3.     TML's C Language Card Image Package  v1.1
  4.     January, 1993
  5.     Todd M. Lewis             (919) 776-7386
  6.     2601 Piedmont Drive
  7.     Sanford, NC  27330-9437
  8.     USA
  9. ************************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <intuition/intuition.h>
  13. #include <graphics/gfxbase.h>
  14. #include <graphics/gfxmacros.h>
  15. #include "CardHImages.h"
  16. #include "Cards.h"
  17.  
  18. #ifdef AZTEC_C
  19.   #include <functions.h>
  20. #endif
  21. #ifdef __SASC
  22.   #include <clib/graphics_protos.h>
  23. #endif
  24.  
  25. /**********************************************************************
  26. CardHBrush.c contains an array of UWORDs which holds the bitmap
  27. data for a deck of playing cards layed out in eight columns.  In
  28. all, 56 cards are defined in the following order:
  29.  
  30.   Spades Hearts  Clubs  Diamonds  Spades Hearts  Clubs  Diamonds
  31.     A       A       A       A       2       2       2       2
  32.     3       3       3       3       4       4       4       4
  33.     5       5       5       5       6       6       6       6
  34.     7       7       7       7       8       8       8       8
  35.     9       9       9       9      10      10      10      10
  36.     J       J       J       J       Q       Q       Q       Q
  37.     K       K       K       K     JOKER   BLANK   BACK    BLACK
  38.  
  39. Each card is 64 bits wide and 18 bits high, the edges of the cards
  40. do not overlap, so the total bitmap is 519(h)x125(v)x2 planes deep. In
  41. addition, another bitplane is defined which has the same shape as the 2
  42. mentioned above, but with all the pixels within the cards turned on. This
  43. bitplane is used as a mask with BltMaskBitMapRastPort() to round off the
  44. corners of the cards.
  45.  
  46. MAKE SURE THE CardHBrush DATA GET LOADED INTO CHIP RAM!  You may
  47. have to edit CardHBrush.c to add the "__chip" keyword, or you
  48. may have to use a link option, or run the ATOM facility on the
  49. final executable to make it load into chip ram.
  50.  
  51. The cards were designed with the following pen colors:
  52.  
  53.   pen | red  green blue
  54.   ----+----------------
  55.     0 |   0     4    12   (Blue)
  56.     1 |   0     0     0   (Black)
  57.     2 |  14    12    10   (Creamy White)
  58.     3 |  15     8     0   (Rusty Red)
  59.  
  60. **********************************************************************/
  61.  
  62. #include "CardHBrush.c"
  63.  
  64. struct  Image CardHBrushimage =
  65.  {
  66.    0,0,
  67.    512 , 126 , 3 ,
  68.    &CardHBrush[0],
  69.    0x1f,0x00,
  70.    NULL,
  71.  };
  72.  
  73. extern struct GfxBase *GfxBase;
  74.  
  75. BOOL ShowHCard( struct RastPort *rp, CardID_t Card, WORD dx, WORD dy )
  76.   {
  77.  
  78.     static struct BitMap bm;
  79.     static BOOL   bmInit = FALSE;
  80.     static UWORD *mask;
  81.     WORD          SourceX, SourceY;
  82.     WORD          suit, rank,x,y;
  83.  
  84.     if (!bmInit)
  85.       {
  86.         PLANEPTR tmp;
  87.         InitBitMap( &bm, 2L, 512L, 126L);
  88.         bm.Planes[0] = (PLANEPTR)&CardHBrush [ 0 ];
  89.         bm.Planes[1] = (PLANEPTR)&CardHBrush1[ 0 ];
  90.         mask         =           &CardHBrush2[ 0 ];
  91.  
  92.         /** Black and White are reversed prior to v35, so swap planes. **/
  93.         if ( CardColorSwapping && GfxBase->LibNode.lib_Version < 35 )
  94.           {
  95.             tmp = bm.Planes[0];
  96.                   bm.Planes[0] = bm.Planes[1];
  97.                                  bm.Planes[1] = tmp;
  98.           }
  99.         bmInit = 1;
  100.       }
  101.  
  102.     if ( Card == CARD_NONE ) /* Erase the card */
  103.       {
  104.         BYTE FgPen, DrawMode;
  105.         UBYTE Mask;
  106.         FgPen    = rp->FgPen;
  107.         DrawMode = rp->DrawMode;
  108.         Mask     = rp->Mask;
  109.         SetAPen( rp, 0 );
  110.         SetDrMd( rp, JAM1 );
  111.         SetWrMsk(rp, 0xff );
  112.         RectFill(rp, dx, dy, dx+CARD_H_WIDTH-1, dy+CARD_H_HEIGHT-1 );
  113.         SetWrMsk(rp, Mask );
  114.         SetDrMd( rp, DrawMode );
  115.         SetAPen( rp, FgPen );
  116.         return TRUE;
  117.       }
  118.  
  119.     if ( !(rank = CardRank( Card )) || !(suit = CardSuit( Card )) )
  120.       return FALSE;
  121.  
  122.     if ( suit == SUIT_SPECIAL )
  123.         {
  124.           y = 6;
  125.           x = 3 + rank;
  126.         }
  127.       else
  128.         {
  129.           x = (suit - 1) + (rank&1? 0 : 4 );
  130.           y = (rank - 1) / 2;
  131.         }
  132.  
  133.     SourceX = x * CARD_H_WIDTH;
  134.     SourceY = y * CARD_H_HEIGHT;
  135.  
  136.     BltMaskBitMapRastPort(
  137.        &bm,                                     /* Source BitMap */
  138.        SourceX,                                 /* Source X      */
  139.        SourceY,                                 /* Source Y      */
  140.        rp,                                      /* destRastPort  */
  141.        dx, dy,                                  /* destX, destY  */
  142.        CARD_H_WIDTH, CARD_H_HEIGHT,             /* sizeX, sizeY  */
  143.        0x00E0,                                  /* minterm       */
  144.        (APTR)mask                               /* bltMask       */
  145.        );
  146.  
  147.     return TRUE;
  148.   }
  149.  
  150.  
  151.